package ltd.newbee.mall.config;

import lombok.extern.slf4j.Slf4j;
import ltd.newbee.mall.service.NewBeeMallOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
@Slf4j
public class OrderCancelTaskConfig {

    @Autowired
    private NewBeeMallOrderService orderService;

    // 每5分钟执行一次，检查超时订单
    @Scheduled(fixedRate = 5 * 60 * 1000) // 5分钟
    public void cancelOvertimeOrders() {
        try {
            orderService.autoCancelOvertimeOrders();
        } catch (Exception e) {
            log.error("自动取消超时订单任务执行失败", e);
        }
    }
}
